package com.wechat.server.mp.config;

import cn.hutool.extra.ftp.FtpConfig;
import cn.hutool.extra.ssh.Sftp;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

import java.nio.charset.StandardCharsets;

/**
 * @description: ftp配置
 * @author: stone
 * @date: Created by 2024/3/16 21:19
 * @version: 1.0.0
 * @pakeage: com.weather.common.ftp.config
 */
@Data
@Configuration
@ConfigurationProperties(prefix = "ftp.client")
public class FtpClientConfig {

    // 默认进入的路径
    String workingDirectory;
    // 主机地址
    String host;
    // 主机端口
    int port;
    // 主机用户名
    String username;
    // 主机密码
    String password;


    @Bean
    public FtpConfig ftpConfig() {
        FtpConfig config = new FtpConfig();
        config.setCharset(StandardCharsets.UTF_8);
        config.setPort(port);
        config.setHost(host);
        config.setPassword(password);
        config.setUser(username);
        config.setConnectionTimeout(30000);
        config.setSoTimeout(30000);
        return config;
    }

    @Bean
    @Scope("prototype")
    public Sftp myFtp(FtpConfig config) {
        return new Sftp(config);
    }

}
